﻿Imports Microsoft.VisualBasic
Imports Oracle.DataAccess.Client
Imports System.ComponentModel
Imports System.Data
Public Class Facultades
    Inherits BDDatos
    Sub New()
        Me.Tabla = "Facultad"
        Me.Vista = "Facultad"
    End Sub
    Public CODIGO As String
    Public NOMBRE As String
    Public DECANO As String
    Public CODIGO_PK As String
    Public Function Insert() As String
        Dim msg As String
        Me.Conectar()
        Try
            Dim querystring As String = "Insert into Facultad(Cod_Facultad,Nom_Facultad,Decano)values(:Cod_Facultad,:Nom_Facultad,:Decano)"
            Me.CrearComando(querystring)
            Me.AsignarParametroCadena(":Cod_Facultad", UCase(CODIGO))
            Me.AsignarParametroCadena(":Nom_Facultad", UCase(NOMBRE))
            Me.AsignarParametroCadena(":Decano", UCase(DECANO))
            Dim numfilas As String = EjecutarComando()
            msg = "Se realizó la insercion exitosamente-" & numfilas
        Catch ex As Exception
            msg = "Error: " & ex.Message
        Finally
            Me.Desconectar()
        End Try
        Return msg
    End Function
    Public Function Delete() As String
        Dim msg As String
        Me.Conectar()
        Try
            Me.querystring = "Delete From Facultad Where Cod_Facultad =:Codigo_PK"
            Me.CrearComando(querystring)
            Me.AsignarParametroCadena(":Codigo_PK", CODIGO_PK)
            'Throw New Exception(querystring)
            Dim numfilas As String = EjecutarComando()
            msg = "Se Eliminó el registro exitosamente-" & numfilas
        Catch ex As Exception
            msg = "Error: " & ex.Message
        Finally
            Me.Desconectar()
        End Try
        Return msg
    End Function
    Public Function Update() As String
        Dim msg As String
        Me.Conectar()
        Try
            Me.querystring = "Update Facultad set Cod_Facultad=:Cod_Facultad, Nom_Facultad=:Nom_Facultad, Decano=:Decano Where Cod_Facultad =:Codigo_PK"
            Me.CrearComando(querystring)
            Me.AsignarParametroCadena(":Cod_Facultad", UCase(CODIGO))
            Me.AsignarParametroCadena(":Nom_Facultad", UCase(NOMBRE))
            Me.AsignarParametroCadena(":Decano", UCase(DECANO))
            Me.AsignarParametroCadena(":Codigo_PK", CODIGO_PK)
            'Throw New Exception(querystring)
            Dim numfilas As String = EjecutarComando()
            msg = "Se Actualizó el registro exitosamente- [" & numfilas & "] Filas Afectadas"
        Catch ex As Exception
            msg = "Error: " & ex.Message
        Finally
            Me.Desconectar()
        End Try
        Return msg
    End Function
    <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
    Public Function consultar(ByVal busc As String) As DataTable
        Me.Conectar()
        If Not String.IsNullOrEmpty(busc) Then
            Me.querystring = "select * from Facultad where upper(cod_facultad) like :Buscar or upper(nom_facultad) like :Buscar or decano like :Buscar"
            CrearComando(querystring)
            Me.AsignarParametroCadena(":Buscar", "%" & UCase(busc) & "%")
            Me.AsignarParametroCadena(":Buscar", "%" & UCase(busc) & "%")
            Me.AsignarParametroCadena(":Buscar", "%" & UCase(busc) & "%")
        Else
            Me.querystring = "select * from Facultad"
            CrearComando(querystring)
        End If
        Dim dt As DataTable = EjecutarConsultaDataTable()
        Me.Desconectar()
        Return dt
    End Function

    Public Function consultarPorCod(ByVal Codigo As String) As DataTable
        Me.Conectar()
        Me.querystring = "select * from Facultad where Cod_facultad = '" & Codigo & "'"
        CrearComando(querystring)
        Dim dt As DataTable = EjecutarConsultaDataTable()
        Me.Desconectar()
        Return dt
    End Function


    Public Shared Function consultarPorParametro(ByVal cedula As String) As DataTable
        'declarmos variable local'
        Dim dt As New DataTable
        Dim sentencia As String
        sentencia = "select * from Afiliados where CEDULA = :CEDULA"
        dt = Datos.RegresarDatos(sentencia)
        Return dt
    End Function
End Class
